package com.wntms.zjy.web;

import com.github.pagehelper.PageInfo;
import com.wntms.zjy.dao.FreightContractDaoz;
import com.wntms.zjy.pojo.CustomerComplain;
import com.wntms.zjy.pojo.CustomerReply;
import com.wntms.zjy.pojo.FreightContract;
import com.wntms.zjy.pojo.Result;
import com.wntms.zjy.service.CustomerReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xzbz
 * @create 2022-11-22 16:48
 */
@RestController
@RequestMapping("/reply")
public class CustomerReplyController {
    @Autowired
    public CustomerReplyService customerReplyService;

    @Autowired
    public FreightContractDaoz freightContractDaoz;
    @GetMapping
    public Result findAll(){
        List<CustomerReply> customerReplies = customerReplyService.findAll();
        if(customerReplies == null){
            return Result.error("服务器错误");
        }else{
            return Result.success(customerReplies,"执行成功");
        }

    }
    @PostMapping("/{fid}")
    public Result findByFid(@PathVariable String fid){
        CustomerReply customerReply = customerReplyService.findByFid(fid);
        if(customerReply == null){
            return Result.error("");
        }else{
            return Result.success(customerReply,"执行成功");
        }

    }
    @GetMapping("/{currentPage}/{pageSize}")
    private Result findByPage(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        List<CustomerReply> customerReplies = customerReplyService.findByPage(currentPage, pageSize);
        if(customerReplies == null){
            return Result.error("服务器错误");
        }else{
            PageInfo<CustomerReply> pageInfo = new PageInfo<>(customerReplies);
            return Result.success(pageInfo,"执行成功");
        }


    }

    @PostMapping()
    public Result addNewReply(@RequestBody CustomerReply customerReply){
        boolean flag = customerReplyService.addNewReply(customerReply);
        if(!flag){
            return Result.error("服务器错误");
        }else{
            return Result.success(null,"执行成功");
        }
    }

    @DeleteMapping("/{id}")
    public Result deleteReply(@PathVariable Integer id){
        boolean flag = customerReplyService.deleteReply(id);
        if(!flag){
            return Result.error("服务器错误");
        }else{
            return Result.success(id,"执行成功");
        }
    }

}
